package com.myjob.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.myjob.entity.Member;
import com.myjob.mapper.MemberMapper;
import com.myjob.response.Result;
import com.myjob.service.MemberService;
import com.myjob.utils.UtilValidate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Chen Yuan
 * @create 2021-01-23  15:11
 */
@Service
public class MemberServiceImpl implements MemberService {
	@Autowired
	private MemberMapper memberMapper;

	/**
	 * 查询所有的会员信息
	 */
	@Override
	public Result selectAllMembers() {
		List<Member> members = memberMapper.selectList(null);
		return Result.succeed(members);
	}

	/**
	 * 按照会员类型的名称查询会员信息
	 * @param typeName 会员类型名称
	 */
	@Override
	public Member selectOneMember(String typeName) {
		if (UtilValidate.isEmpty(typeName)){
			return null;
		}
		QueryWrapper<Member> wrapper = new QueryWrapper<>();
		wrapper.eq("type_name", typeName);
		Member member = memberMapper.selectOne(wrapper);
		return member;
	}

	@Override
	public int updateMember(Member member) {
		if (UtilValidate.isEmpty(member)){
			return -1;
		}
		return memberMapper.updateById(member);
	}
}
